package controller;

import dao.IUserDao;
import dao.impl.UserDaoImpl;
import service.IUserService;
import service.impl.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class RegServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();;
        String name=request.getParameter("username");
        String pwd=request.getParameter("password");

        IUserService iud=new UserService();
        if(iud.register(name,pwd)>0){

            out.print("<script>alert('注册成功');location.href='login.html';</script>");
        }else {
            out.print("<script>alert('注册失败,请查看!');location.href='reg.html';</script>");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }
}

